#include <stdio.h>
#include <string.h>
#include "worker.h"
#include "worker_imp.h"

static void _V_Say(ObjectPtr obj, const char* text) {
    Worker *p = (Worker*)obj;
    printf("%s | %s, age: %d, job:%s, property: %d\n",
           text, p->data.s._name, p->data.s._age, p->data._job, p->data._property);
}

static void _V_WorkForYear(ObjectPtr obj) {
    Worker *p = (Worker*)obj;
    p->data.s._age ++;
    p->data._salary += 1000;  //! 工资涨1000元
    p->data._property += p->data._salary;  //! 存款涨了
    printf("I am %s, property:%d\n", p->data._job, p->data._property);
}

void Worker_VFuncInit(Worker_Func *vfunc) {
    Person_VFuncInit((Person_Func*)vfunc);
    vfunc->s._Say = _V_Say;
    vfunc->s._WorkForYear = _V_WorkForYear;
}

#define PARAM_LIST      PARAM_LIST_2
#define TYPE_PARAM_LIST C_TYPE_PARAM_LIST_2(const char*, int)
BASE_FUNC_DEFINE(Worker, Person, OOP);
#undef TYPE_PARAM_LIST
#undef PARAM_LIST

void Worker_Construct(ObjectPtr obj, const char* name, int age) {
    OOP_ASSERT(is_instance_of(obj, ClassID_Worker));
    Person_Construct(obj, name, age);

    Worker_Data *data = (Worker_Data*)(obj+1);
    data->_salary = 0;
    data->_job[0] = '\0';
}

void Worker_Destruct(ObjectPtr obj) {
    OOP_ASSERT(is_instance_of(obj, ClassID_Worker));

    Person_Destruct(obj);
}

void Worker_SetJob(ObjectPtr obj, const char *job, int salary) {
    Worker_Data *data = (Worker_Data*)(obj+1);
    strcpy(data->_job, job);
    data->_salary = salary;
}
